//
//  ListMdel.m
//  Slice
//
//  Created by lanou on 16/6/16.
//  Copyright © 2016年 wangjinchao. All rights reserved.
//

#import "ListMdel.h"

@implementation ListMdel

- (instancetype)initWithName:(NSString *)name title:(NSString *)title content:(NSString *)content coverimg:(NSString *)coverimg id:(NSString *)id1 {
    self = [super init];
    if (self) {
        self.name = name;
        self.title = title;
        self.content = content;
        self.coverimg = coverimg;
        self.id = id1;
    }
    return self;
}


- (void)encodeWithCoder:(NSCoder *)aCoder {
    [aCoder encodeObject:self.name forKey:@"name"];
    [aCoder encodeObject:self.title forKey:@"title"];
    [aCoder encodeObject:self.content forKey:@"content"];
    [aCoder encodeObject:self.coverimg forKey:@"coverimg"];
    [aCoder encodeObject:self.id forKey:@"id"];

}

- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
    NSString *name = [aDecoder decodeObjectForKey:@"name"];
    NSString *title = [aDecoder decodeObjectForKey:@"title"];
    NSString *content = [aDecoder decodeObjectForKey:@"content"];
    NSString *coverimg = [aDecoder decodeObjectForKey:@"coverimg"];
    NSString *id1 = [aDecoder decodeObjectForKey:@"id"];

    return [self initWithName:name title:title content:content coverimg:coverimg id:id1];
}


//归档与反归档的方法
+ (NSData *)achiveWithModel:(ListMdel *)model {
    NSMutableData *data = [NSMutableData data];
    
    NSKeyedArchiver *archier = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
    
    [archier encodeObject:model forKey:model.title];
    
    [archier finishEncoding];
    
    return data;
}
//反归档
+ (ListMdel *)notAchicerWithData:(NSData *)data key:(NSString *)key {
    
    NSKeyedUnarchiver *unAchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
    
    ListMdel *lisModel  =  [unAchiver decodeObjectForKey:key];
    
    return lisModel;
}
















-(void)setValue:(id)value forUndefinedKey:(NSString *)key {
    if ([value isEqualToString:@"id"]) {
        [self setValue:value forUndefinedKey:key];
    }
}


+ (instancetype)modelWithDiction:(NSDictionary *)dic {
    [super modelWithDiction:dic];
    ListMdel *model = [[ListMdel alloc] init];
    [model setValuesForKeysWithDictionary:dic];
    return model;
}








@end
